//
//  MHAccountSecurityViewController.m
// MiaoCircle
//
//Created by acgera on 2018/4/9.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHAccountSecurityViewController.h"
#import "MHCommonRightButtonCell.h"

@interface MHAccountSecurityViewController ()
/// viewModel
@property (nonatomic, readonly, strong) MHAccountSecurityViewModel *viewModel;
@end

@implementation MHAccountSecurityViewController

@dynamic viewModel;

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath{
    MHCommonRightButtonCell *cell = [MHCommonRightButtonCell cellWithTableView:tableView];
//    __weak __typeof(self)weakSelf = self;

    if (indexPath.row == 1) {
        [cell.rightButton setTitle:@"已绑定" forState:0];

        cell.rightButton.enabled = false;
    }else
    {
        @weakify(self);
        [RACObserve([MHHTTPService sharedInstance].currentUser, bindPhone) subscribeNext:^(NSString *bind) {
            @strongify(self);
            if (bind.length > 0) {
                 [cell.rightButton setTitle:@"修改" forState:0];
            }else
            {
                 [cell.rightButton setTitle:@"绑定" forState:0];
            }
        }];
       
        [cell.rightButton bk_whenTapped:^{
            @strongify(self);
            [self.viewModel.bindOrModifyPhoneNumberCommand execute:nil];
        }];
        cell.rightButton.enabled = true;
    }
    MHCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
    id object = groupViewModel.itemViewModels[indexPath.row];
    [cell setIndexPath:indexPath rowsInSection:groupViewModel.itemViewModels.count];
    [self configureCell:cell atIndexPath:indexPath withObject:(id)object];
    [cell setNeedsLayout];
    [cell layoutIfNeeded];
//    cell.priceTextFeild.text = [NSString stringWithFormat:@"%@",[@(self.viewModel.circleInfo.joinPrice ?: 0) stringValue]];
//    cell.priceTextFeild.bk_shouldEndEditingBlock = ^BOOL(UITextField *textFeild) {
//        weakSelf.viewModel.circleInfo.joinPrice = [cell.priceTextFeild.text integerValue];
//        return YES;
//    };
    
    return cell;
}



@end
